home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-18 | 2.7 KB | 112 lines | [TEXT/R*ch] |
- Split up your scripting projects. Use the load script command to load
- pre-compiled portions of your script project. If you’re using Script Editor,
- Script Wizard, FaceSpan or Scripter, it’s probably best to store your
- pre-compiled scripts in a known location so that you can use simple Load Script
- statements:
-
- property lib1 : load script alias "My HD:Script Libraries:Lib1"
-
- Alternatively, you can store your libraries in the same folder as your
- script editor, and load them with the following command:
-
- property lib1 : load script "Lib1"
-
- If you’re using Script Debugger, you can use its path to me handling to
- store your libraries in a folder with your script:
-
- property projectPath :¬
- «property ctnr» of item (path to me) of ¬
- application "Finder" as string
- property lib1 : load script (projectPath & "Lib1")
- Once you’ve loaded your library, you can access properties and call handlers
- stored within it like this:
-
- propertyName of lib1
-
- handlerName(p1, p2, p3) of lib1
-
- ***
-
-
-
-
- The slow way:
-
- tell application "Finder"
- repeat with aItem in (items of first window)
- if name of aItem ends with ".temp" then
- delete aItem
- end
- end
- end
-
- The fast way:
-
- tell application "Finder"
- delete (items whose name ends with ".temp") ¬
- of first window
- end
-
- The next error people commonly make is to repeatedly ask for the value of
- properties. For example, you might do the following:
-
- tell application "Finder"
- repeat with aItem in items of window 1
- if name of aItem ends with ".c" or ¬
- name of aItem ends with ".h" then
- -- do something with .c and .h files
- end
- end
- end
-
- This script fragment gets the value of the application’s name property
- twice. A faster method is to get the name property once:
-
- tell application "Finder"
- repeat with aItem in items of window 1
- set theFileName to name of aItem
- if theFileName ends with ".c" or ¬
- theFileName ends with ".h" then
- -- do something with .c and .h files
- end
- end
- end
-
-
- ***
-
-
- So, in the following example, the current date command (which is a scripting
- addition command) is executed within the Scriptable Text Editor’s process rather
- than the applet:
-
- tell application "Scriptable Text Editor"
- make new line at end of first window ¬
- with data (current date as string)
- end
-
- An improvement in speed would result if you did it this way:
-
- set theData to current date as string
- tell application "Scriptable Text Editor"
- make new line at end of first window ¬
- with data theData
- end
-
- If you are deep within a tell block, you could deal with the problem this
- way:
-
- tell application "Scriptable Text Editor"
- ...
- make new paragraph at end of first window with ¬
- data ((current date) of me as string)
- ...
- end
-
-
-
- ***
-
-
-
-